
import 'package:syn_4s/core/constants/sp_key.dart';
import 'package:syn_4s/core/model/base/api_result_data.dart';
import 'package:syn_4s/core/model/map_all_device_model.dart';
import 'package:syn_4s/core/utils/sp_utils.dart';

import '../utils/dio_utils.dart';

class GoogleMapRequest{
  static Future<ApiResultData<List<MapAllDeviceModel>>> getAllDevice(String tagCode) async {
    var projCode = await SPUtils.get(keyProjCode);
    tagCode = tagCode.replaceAll(" ", "").replaceAll("[", "").replaceAll("]", "");
    // var projCode = "demo";
    final url = "/api/Dashboards/GetAllDevice?projCode=$projCode&tagCode=$tagCode";
    final result = await DioUtils.instance.requestBaseUrl(url);

    List<Map<String, dynamic>> data = (result['data'] as List).cast<Map<String, dynamic>>();

    List<MapAllDeviceModel> deviceModels = data.map((item) => MapAllDeviceModel.fromJson(item)).toList();

    ApiResultData<List<MapAllDeviceModel>> apiResultData = ApiResultData<List<MapAllDeviceModel>>(
      data: deviceModels,
      status: result['status'],
      message: result['message'],
    );
    return apiResultData;
  }

  static Future<ApiResultData<MapAllDeviceModel>> getDeviceDetails(String tagCode, String id) async {
    var projCode = await SPUtils.get(keyProjCode);
    // var projCode = "demo";

    final url = "/api/Dashboards/Details?projCode=$projCode&tagCode=$tagCode&id=$id";

    final result = await DioUtils.instance.requestBaseUrl(url);

    ApiResultData<MapAllDeviceModel> apiResultData =
    ApiResultData<MapAllDeviceModel>.fromJson(result, MapAllDeviceModel.fromJson);
    return apiResultData;
  }
}